const App = {
    data() {
        return {
            photo,
            nodeKey: '',
            activeName: '',
            Category: [],
            dataForm:{

            },
            tableData: [],
            form: {
                Page: 1,
                Limit: 100,
                Condition: '',
            },
            Total: 0,
            loading: false,
            relativePath:'',
        }
    },
    mounted() {
        let ls_URL = window.location.href;
        this.nodeKey = getQueryObject(ls_URL, "nodeKey");// 获取 nodeKey 参数
        currentURL = ls_URL.replace(/([?&])ACCESSTOKEN=[^&]*(&|$)/, '$1').replace(/[?&]$/, '')
        this.relativePath = currentURL.substring(
            currentURL.lastIndexOf("view"),
            currentURL.length
        );
        this.getCategory();
        this.getData(this.nodeKey);
    },
    methods: {
        handleSizeChange(newSize) {
            this.form.Page = 1;
            this.form.Limit = newSize;
            this.getList(this.form);
        },
        handleCurrentChange(newPage) {
            this.form.Page = newPage;
            this.getList(this.form);
        },
        getCategory() {
            this.loading = true;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    SQLSerialNumber: 't_merchant_business_scope1',
                    Condition: '',
                    ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND merchant_business_scope.Merchant_SerialNumber = '" + this.nodeKey + "'"))),
                },
                success: (res) => {
                    this.activeName = res[0] ? res[0].Merchant_Mapping_Blue_Plate_SerialNumber : '';
                    this.Category = res;
                    if (res.length > 0) {
                        this.getList()
                    }
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        getData(nodeKey) {//查询
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'merchant',
                    Condition: `Merchant_SerialNumber='${nodeKey}'`,
                },
                success: (res) => { 
                    this.dataForm = res[0];
                    console.log(this.dataForm);
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
            })
        },
        getList() {
            this.loading = true;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    SQLSerialNumber: 't_room_type1',
                    Condition: window.btoa(unescape(encodeURIComponent(this.activeName + "," + this.nodeKey))),
                },
                success: (res) => {
                    this.tableData = res;
                },
                complete: (XMLHttpRequest) => {
                    this.loading = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        handleAdd() {
            let obj = this.Category.filter(i=>i.Merchant_Mapping_Blue_Plate_SerialNumber==this.activeName)[0];
            window.location.href = './add1.html?action=Add&nodeKey1=' + this.nodeKey + '&nodeKey2=' + this.activeName + '&nodeKey3=' + obj.Merchant_Category_SerialNumber + '&nodeKey4=' + obj.Blue_Plate_SerialNumber;
        },
        handleEdit(row) {
            let obj = this.Category.filter(i=>i.Merchant_Mapping_Blue_Plate_SerialNumber==this.activeName)[0];
            window.location.href = './add1.html?action=Modify&nodeKey=' + row.Room_Type_SerialNumber + '&nodeKey1=' + this.nodeKey + '&nodeKey2=' + this.activeName + '&nodeKey3=' + obj.Merchant_Category_SerialNumber + '&nodeKey4=' + obj.Blue_Plate_SerialNumber;
        },
        handleDelete(data) {
            this.$confirm('该操作将删除此条数据,是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    method: "post",
                    data: {
                        Data: 'room_type',
                        Condition: "Room_Type_SerialNumber='" + data.Room_Type_SerialNumber + "'"
                    },
                    success: (res) => {
                        if (res.length == 1) {
                            res[0].Row_Status = '1';
                            let lJSONObject_DataSet = new Object();
                            let lJSONObject_Table = new Object();
                            lJSONObject_Table['room_type'] = res;
                            lJSONObject_DataSet['Modify'] = lJSONObject_Table;
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            lJSONObject_DataSet['Add'] = new Object();
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSaveByRequestBody",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet, (res) => {
                                if (res.Status == 'success') {
                                    this.postgetList(this.page);
                                    this.$message({
                                        type: 'success',
                                        message: '删除成功'
                                    });
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '删除失败'
                                    });
                                }
                            })
                        } else {
                            this.$message({
                                type: 'error',
                                message: '删除失败'
                            });
                        }

                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest)
                    },
                });
            }).catch(() => { });
        },
        goBack() {
            window.history.back();
        },
        reset() {
            window.location.reload();
        },
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-select', ylSelect);
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
